/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 杨已萱
 * Date: 2023-03-25
 * Time: 22:27
 */


     class Animal {
        String name;
        int age;

    public Animal() {
        System.out.println("父类无参构造");
    }

    public Animal(String name, int age){
            this.name = name;
            this.age = age;
          }
         public void eat(){
            System.out.println(name + "吃饭");
        }
    }
     class Cat extends Animal{
         public Cat (){
             super.age = 10;
             super.name = "小猫";

         }
//        public Cat(String name, int age){
//            super(name, age);
//        }
        @Override
        public void eat(){
            System.out.println(name+"吃鱼~~~");
        }
    }
   class Dog extends Animal {
        public Dog(String name, int age){
            super(name, age);
        }
        @Override
        public void eat(){
            System.out.println(name+"吃骨头~~~");
        }
    }
  public class TestAnimal {
        public static void eat (Animal a) {
            a.eat();
        }
//            public static void main(String[] args) {
//                Cat cat = new Cat("元宝",2);
//                Dog dog = new Dog("小七", 1);
//                eat(cat);
//                eat(dog);

            public static void main(String[]args){
                Animal animal = new Cat();
                Animal animal2 = new Dog("旺财", 1);
//                eat(animal);
//                eat(animal2);
////
                animal.eat();
                animal2.eat();
            }

}


